{
 "cells": [
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "## 枚举",
   "id": "455f2fae85b3f911"
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "",
   "id": "6d6066a42e479c8a"
  },
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-02-25T06:07:17.763496Z",
     "start_time": "2025-02-25T06:07:17.740892Z"
    }
   },
   "source": [
    "# 找出1-100之间的素数\n",
    "import math\n",
    "def pd(x):\n",
    "    if(x<=1):\n",
    "        return False\n",
    "    y=int(math.sqrt(x))\n",
    "    for i in range(2,y+1): \n",
    "        if x%i==0:\n",
    "            return False\n",
    "    return True\n",
    "\n",
    "cnt=0\n",
    "for i in range(1,101):\n",
    "    if pd(i):\n",
    "        print(i,end=' ')\n",
    "        cnt+=1\n",
    "print()\n",
    "print(\"总共有\",cnt,\"个素数\")"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 \n",
      "总共有 25 个素数\n"
     ]
    }
   ],
   "execution_count": 4
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
